package com.ocom.xcxapi.controller;

import com.ocom.common.constant.CompanyServiceUrl;
import com.ocom.common.resp.Result;
import com.ocom.common.utils.DateUtil;
import com.ocom.common.vo.recode.AccessRecordVo;
import com.ocom.security.utils.SecurityUtils;
import com.ocom.xcxapi.client.MjRecodeClientService;
import com.ocom.xcxapi.service.AccessService;
import com.ocom.xcxapi.util.NumConvertUtil;
import com.ocom.xcxapi.vo.MenjinGetRecordVo;
import lombok.extern.log4j.Log4j;
import org.apache.commons.codec.binary.Base64;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.Date;


//@PreAuthorize("hasRole('ROLE_XCX')")
@RestController
@Log4j
public class RecordController {


    @Autowired
    private MjRecodeClientService mjRecodeClientService;
    /**
     * 2.9.获取设备开门记录 menjin/getRecord
     * */
    @PostMapping(CompanyServiceUrl.URL_MenjinGetRecord)
    public Result MenjinGetRecord(@RequestBody @Validated AccessRecordVo accessRecordVo){
        accessRecordVo.setBeginTime(DateUtil.getDateTime(DateUtil.addDays(new Date(),-30)));
        accessRecordVo.setPage(0);
        accessRecordVo.setSize(10);
        return mjRecodeClientService.GetAccessRecord(accessRecordVo);
    }


    public static void main(String[] args ){

        String testString = "WEFLbwgAAAAuAQAAJAYJAQEAAAAAAABiKbsNAQUuQBPYLqUzyfkW+KkFnFsKNlYHZ6TsDkEXFJn+s/mMetT3JS02/FdPMvUZv8ZukgjMkqexuBos+nEZ4YBQXk3U2A==";

//        System.out.println(NumConvertUtil.bytesToHexString(Base64.getDecoder().decode(testString)));
//
        String y="58414b6f080000002e01000024060901010000000000006229bb0d01052e4013d82ea533c9f916f8a9059c5b0a36560767a4ec0e41171499feb3f98c7ad4f7252d36fc574f32f519bfc66e9208cc92a7b1b81a2cfa7119e180505e4dd4d8";
//        byte[] bytes=new byte[94];
//        for (int i=0;i<93;i++){
//            bytes[i]=NumConvertUtil.HexStringToInt(y.substring(i*2,(i+1)*2)).byteValue();
//        }
//        System.out.println(NumConvertUtil.bytesToHexString(Base64.getEncoder().encode(bytes)));
        byte[] stringByte222 = NumConvertUtil.hexStringToByte(y);
        System.out.println(Base64.encodeBase64String(stringByte222));


        byte[] stringByte = testString.getBytes();
        byte[] base64Byte = Base64.decodeBase64(testString);


        System.out.println(NumConvertUtil.bytesToHexString(base64Byte));

        System.out.println("原字符串："+testString);
        System.out.println("stringByte："+ Arrays.toString(stringByte));
        System.out.println("base64Byte："+ Arrays.toString(base64Byte));

        //还原字符串
        System.out.println("还原stringByte："+new String(stringByte));
        System.out.println("还原base64Byte："+ Base64.encodeBase64String(base64Byte));



    }
}
